$(function(){

	var wsUrl = "ws://103.21.142.12:50272";
	var websocket = new WebSocket(wsUrl);

	websocket.onopen = function(){
	}

	websocket.onmessage = function(event){
		push(event.data);
	}

	websocket.onclose = function(event){
		console.log("close");
	}

	websocket.onerror = function(event,error){
		console.log('error');
	}


	function push(data){
		var jsonData = JSON.parse(data);

		var html = '';
		html += '<div class="comment"><span>用户'+jsonData.user_id+'说：</span><span>'+jsonData.content+'</span></div>';
		$("#comments").prepend(html);
	}
});